package org.sgx.gwtsjcltest.client;

import org.sgx.gwtsjcl.client.SJCL;
import org.sgx.gwtsjcl.client.SJCLLoader;

import com.google.gwt.core.client.Callback;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Window;

public class GWTSJCLTestEntryPoint implements EntryPoint {

	@Override
	public void onModuleLoad() {

		// testOther();

		// testEmbedded();
		// testNotEmbeddedUrl();
		testNotEmbedded();
	}

	private void testNotEmbedded() {
		SJCLLoader.load(new Callback<Void, Exception>() {
			@Override
			public void onSuccess(Void result) {
				// ready to work
				String password = "banana4", plainText = "En algún lugar de la mancha not embedded";
				SJCL sjcl = SJCL.sjcl();
				String encrypted = sjcl.encrypt(password, plainText);
				String decrypted = sjcl.decrypt(password, encrypted);
				System.out.println(encrypted + " - " + decrypted);
			}
		
			@Override
			public void onFailure(Exception reason) {
				Window.alert("Couldn't load SJCL Library from http://crypto.stanford.edu/sjcl/");
			}
		});
	}

	// private void testOther() {
	// String scriptUrl = "http://crypto.stanford.edu/sjcl/sjcl.js";
	// SJCLLoader.load(scriptUrl, new Callback<Void, Exception>() {
	// @Override
	// public void onSuccess(Void result) {
	// // ready to work
	// String password = "banana4",
	// plainText = "En algún lugar de la mancha not embedded";
	// SJCL sjcl = SJCL.sjcl();
	// String encrypted = sjcl.encrypt(password, plainText);
	// String decrypted = sjcl.decrypt(password, encrypted);
	// System.out.println(encrypted + " - " + decrypted);
	// }
	//
	// @Override
	// public void onFailure(Exception reason) {
	// Window.alert("Couldn't load SJCL Library from http://crypto.stanford.edu/sjcl/");
	// }
	// });
	// }

	// private void testEmbedded() {
	// String password = "banana4",
	// plainText = "En algún lugar de la mancha - embedded";
	// SJCL sjcl = SJCL.sjcl();
	// String encrypted = sjcl.encrypt(password, plainText);
	// String decrypted = sjcl.decrypt(password, encrypted);
	// System.out.println(encrypted + " - " + decrypted);
	// }
	//
	
	
//	private void testNotEmbeddedUrl() {
//		String scriptUrl = "http://crypto.stanford.edu/sjcl/sjcl.js";
//		SJCLLoader.load(scriptUrl, new Callback<Void, Exception>() {
//			@Override
//			public void onSuccess(Void result) {
//				// ready to work
//				String password = "banana4", plainText = "En algún lugar de la mancha not embedded";
//				SJCL sjcl = SJCL.sjcl();
//				String encrypted = sjcl.encrypt(password, plainText);
//				String decrypted = sjcl.decrypt(password, encrypted);
//				System.out.println(encrypted + " - " + decrypted);
//			}
//
//			@Override
//			public void onFailure(Exception reason) {
//				Window.alert("Couldn't load SJCL Library from http://crypto.stanford.edu/sjcl/");
//			}
//		});
//	}

}
